package cn.com.main;


import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.scheduling.annotation.Async;
import org.springframework.test.context.junit4.SpringRunner;


@RunWith(SpringRunner.class)
@SpringBootTest(classes = SpringBootApplication.class)
public class ThreadpoolTest {


    @Test
    public void testSayHello() throws Exception {
        sayHello();
        sayHello2();
    }

    @Async // 使用异步方法
    @Test
    public void sayHello() {
        System.out.println(Thread.currentThread().getName());
        System.out.println("hello，1");
    }

    @Async("myThreadPool") // 参数为线程池配置时的方法名即对应的bean的id ①
    @Test
    public void sayHello2() {
        System.out.println(Thread.currentThread().getName());
        System.out.println("hello，2");
    }


    @Async("MyThreadPoolTaskExecutor") // 参数为线程池配置时的方法名即对应的bean的id ①
    @Test
    public void sayHello3() {
        System.out.println(Thread.currentThread().getName());
        System.out.println("hello，3");
    }


}
